<?php

class Kd_Data_Dcl_Delete extends Kd_Data_Dcl_Base {

    private $_table = NULL;
    private $_where = NULL;

    public function  __construct() {
        parent::__construct();
        $this->_where = new Kd_Data_Dcl_Expression_Where();
        $this->_where->setOwner($this);
    }
    
    public function __call($name, $arguments) {
        switch ($name) {
            case 'eq':
            case 'lt':
            case 'gt':
            case 'lteq':
            case 'gteq':
            case 'neq':
            case 'like':
            case 'contain':
            case 'not':
            case 'isNull':
            case 'orNext':
            case 'andNext':
                return call_user_func_array(array($this->_where, $name), $arguments)->closest();
        }
    }

    public function getTable(){
        return $this->_table;
    }

    public function getWhere(){
        return $this->_where;
    }

    public function from($table){
        $this->_table = $table;
        return $this;
    }

    public function where(){
        return $this->_where;
    }

    public function toSql(){
        return Kd_Data_Factory::getDeleteParser()->parse($this);
    }

    public function execute(){
        $sql = $this->toSql();
        return $this->getDbDriver()->setSql($sql, $this->getParameters())->execute();
    }
}